Add functionality to construct products in applicative / monadic way#101
Add functionality to construct products in applicative / monadic way#101joroKr21 merged 10 commits intotypelevel:mainfrom
Conversation
96568d2 to
c51430c
Compare
c51430c to
23e7ce3
Compare
4b3c8af to
5646fdd
Compare
48751fc to
0c5f26e
Compare
| value <- fieldMap.get(field).toRight(s"Missing field '$field';") | ||
| parsed <- parser.parse(value, accum) | ||
| yield parsed | ||
| if accum then inst.constructA(parseField)(pure, map, ap) |
There was a problem hiding this comment.
I got so confused as to why constructA and constructM would be different for Either and then realized you're doing naughty things with ap 😂
There was a problem hiding this comment.
Yeah, I didn't want to spend too much time defining Validated so I just used an inconsistent Either
| final def erasedConstructA[F[_]](f: Any => F[Any])(pure: Pure[F], map: MapF[F], ap: Ap[F]): F[Any] = | ||
| traverseProduct(new ArrayProduct(is), (tc, _) => f(tc))(pure, map, ap) | ||
|
|
||
| final def erasedConstructM[F[_]](f: Any => F[Any])(pure: Pure[F], map: MapF[F], tailRecM: TailRecM[F]): F[Any] = |
There was a problem hiding this comment.
Is this just a stacksafe version of constructA or is there some other difference that I've missed?
There was a problem hiding this comment.
constructA is based on Applicative:
- It can be parallel
- It cannot short circuit (evaluates for all fields)
- It is not stack safe (currently) - but it could be optimized if we build a tree instead of a list of
ap
constructM is based on Monad:
- It is always sequential
- It can short circuit
- It is stack safe
There was a problem hiding this comment.
cats.Applicative actually has map2Eval which can short circuit but that's too much complexity for Shapeless
There was a problem hiding this comment.
@TimWSpence here is a failed attempt to make traverse and constructA stack safe: #103
But it doesn't actually build a tree ...
There was a problem hiding this comment.
Sorry, just saw this. Will have a look!
Uh oh!
There was an error while loading. Please reload this page.